package commons;

import java.util.concurrent.Semaphore;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Synchronizer {

	static private Semaphore sem;
	static {
		sem = new Semaphore(1);
	}

	static public void beginCalcul() {
		//System.out.println("_____ Begin calcul _ ASK : " + Thread.currentThread().getName());
		try {sem.acquire();} catch (InterruptedException ex) {}
		//System.out.println("_____ Begin calcul _ OK : " + Thread.currentThread().getName());
	}
	static public void endCalcul() {
		//System.out.println("_____ End calcul : " + Thread.currentThread().getName());
		sem.release();
	}

	static public void beginPaint() {
		//System.out.println("_____ Begin paint _ ASK : " + Thread.currentThread().getName());
		try {sem.acquire();} catch (InterruptedException ex) {}
		//System.out.println("_____ Begin paint _ OK : " + Thread.currentThread().getName());
	}
	static public void endPaint() {
		//System.out.println("_____ End paint : " + Thread.currentThread().getName());
		sem.release();
	}
}
